Do not modify a const GdkEvent in place
authorEmmanuele Bassi <ebassi@gnome.org>
Tue, 26 Jun 2018 16:57:29 +0000 (17:57 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Tue, 26 Jun 2018 17:06:23 +0000 (18:06 +0100)
When deciding whether or not to emulate a press event, we're translating
the last event coordinates and mutating the given event structure
unconditionally.

We should modify the newly created GdkEvent copy, since it's what we're
going to use when emitting the press event.

This avoids mutating a constant GdkEvent and global state, and also
avoids a compiler warning.

gtk/gtkwidget.c

index 234c1302dd0c4fd9d2e964b5e705a2dab33bcf42..2fea7f914351d1b20df2553bfc57005c7c97ed4c 100644 (file)
@@ -2515,7 +2515,6 @@ _gtk_widget_emulate_press (GtkWidget      *widget,
                                      gtk_widget_get_toplevel (event_widget),
                                      x, y,
                                      &x, &y);
-  gdk_event_set_coords (event, x, y);
 
   if (event->any.type == GDK_TOUCH_BEGIN ||
       event->any.type == GDK_TOUCH_UPDATE ||
@@ -2535,8 +2534,6 @@ _gtk_widget_emulate_press (GtkWidget      *widget,
       press = gdk_event_new (GDK_BUTTON_PRESS);
       press->any.surface = g_object_ref (event->any.surface);
       press->button.time = event->motion.time;
-      press->button.x = event->motion.x;
-      press->button.y = event->motion.y;
       press->button.x_root = event->motion.x_root;
       press->button.y_root = event->motion.y_root;
       press->button.state = event->motion.state;
@@ -2563,6 +2560,8 @@ _gtk_widget_emulate_press (GtkWidget      *widget,
   else
     return;
 
+  gdk_event_set_coords (press, x, y);
+
   press->any.send_event = TRUE;
   next_child = event_widget;
   parent = _gtk_widget_get_parent (next_child);